package top.eggcode.system.client.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import top.eggcode.common.mvc.Result;
import top.eggcode.common.mvc.ResultWrapper;
import top.eggcode.system.client.UserClientService;
import top.eggcode.system.client.model.Account;
import top.eggcode.system.client.model.User;

import java.util.Set;

@Component
public class UserClientFactory implements FallbackFactory<UserClientService> {

    private static final Logger logger = LoggerFactory.getLogger(UserClientFactory.class);


    @Override
    public UserClientService create(Throwable cause) {
        logger.error("用户信息调用失败:{}", cause.getMessage());
        return new UserClientService() {
            @PostMapping("/api/user/findByName")
            @Override
            public Result<User> findByName(String username) {
                return ResultWrapper.failure("获取用户信息调用失败" + cause.getMessage());
            }

            @PostMapping("/api/user/power_code_list")
            @Override
            public Result<Set<String>> getPowerCodeList(String username) {
                return ResultWrapper.failure("获取权限码列表调用失败" + cause.getMessage());
            }

            @Override
            public Result<Set<String>> getRoleCodeList(String username) {
                return ResultWrapper.failure("获取角色码列表调用失败" + cause.getMessage());
            }

            @PostMapping("/api/user/account/findByName")
            @Override
            public Result<Account> findAccount(String username) {
                return ResultWrapper.failure("获取账户列表调用失败" + cause.getMessage());
            }
        };
    }
}
